// pages/view/merchantIn/merchantIn.js
import { imgUrl } from '../../../utils/common'
import Toast from '../../../miniprogram_npm/@vant/weapp/toast/toast.js';
Page({

  /**
   * 页面的初始数据
   */
  data: {
    imgUrl: imgUrl,
    username: '',
    usernameTest: true,
    phone: '',
    phoneTest: true,
    merchant: '',
    merchantTest: true,
    address: '',
    addressTest: true,
    addressDetail: '',
    addressDetailTest: true
  },

  // 总校验
  testInfo() {
    let flag = this.testAddress() && this.testUsername() && this.testAddressDetail() && this.testMerchant() && this.testPhone()
    if(flag) {
      Toast.success('提交成功')
      return true
    }else{
      console.log('包水电费')
      Toast.fail('提交失败')
      this.testAddress()
      this.testUsername()
      this.testAddressDetail()
      this.testMerchant()
      this.testPhone()
      return false
    }
  },

  // 校验用户名
  testUsername() {
    if(this.data.username.length >= 2) {
      this.setData({
        usernameTest: true
      })
      return true
    }else {
      this.setData({
        usernameTest: false
      })
      return false
    }
  },
  // 检验手机号
  testPhone() {
    const reg = /^(13[0-9]|14[01456879]|15[0-35-9]|16[2567]|17[0-8]|18[0-9]|19[0-35-9])\d{8}$/
    const flag = reg.test(this.data.phone)
    if(flag) {
      this.setData({
        phoneTest: true
      })
      return true
    }else {
      this.setData({
        phoneTest: false
      })
      return false
    }
  },
  // 校验商家名称
  testMerchant() {
    if(this.data.merchant.length >= 2) {
      this.setData({
        merchantTest: true
      })
      return true
    }else {
      this.setData({
        merchantTest: false
      })
      return false
    }
  },
  // 校验地址
  testAddress() {
    if(this.data.address.length >= 2) {
      this.setData({
        addressTest: true
      })
      return true
    }else {
      this.setData({
        addressTest: false
      })
      return false
    }
  },
  // 校验地址详情
  testAddressDetail() {
    if(this.data.addressDetail.length >= 5) {
      this.setData({
        addressDetailTest: true
      })
      return true
    }else {
      this.setData({
        addressDetailTest: false
      })
      return false
    }
  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad(options) {

  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady() {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow() {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide() {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload() {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh() {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom() {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage() {

  }
})